package main

import (
	"sort"
	"fmt"
)

type Person struct {
	name string
	age int
}

type PersonSlice []*Person

func (s *PersonSlice) Len() int { return len(*s) }

func (s *PersonSlice) Less(i,j int) bool { return (*(*s)[i]).age < (*(*s)[j]).age }

func (s *PersonSlice) Swap(i,j int) { (*s)[i], (*s)[j] = (*s)[j], (*s)[i] }

func main() {
	p1:=&Person{"damao",30}
	p2:=&Person{"xiaomao",25}
	p3:=&Person{"laomao",50}
	s:=&PersonSlice{p1, p2, p3}

	// sort.Sort(s)
	sort.Sort(sort.Reverse(s))

	for i:=0; i < len(*s); i++ {
		fmt.Println( *((*s)[i]) )
	}
}
